<?php
/**
 * Created by PhpStorm.
 * User: toshiba
 * Date: 2015/4/17
 * Time: 17:34
 */

class order extends Activity{
    //订单详情
    function getDetailTask($order_id){
        if(!empty($order_id)){
            $r['data']=OrderMode::init()->getDetail($order_id);
            $r['resultCode']= !empty($r['data']) ? 200:500;
        }else{
            $r['data']=null;
            $r['resultCode']=500;
        }
        View::displayAsJson($r);
    }
    //评论一个订单里的商品
    function addCommentTask($goods_in_order_id,$user_id,$gopen_id,$comment,$score,$pic_ids){
        $r['data']=OrderMode::init()->addComment($goods_in_order_id,$user_id,$gopen_id,$comment,$score,$pic_ids);
        $r['resultCode']= !empty($r['data']) && $r['data']>0 ? 200:500;
        View::displayAsJson($r);
    }
    //一个商品的评论  ...
    function commentListTask($gopen_id,$page,$rows){
        if(empty($gopen_id)){
            $r['data']="gopen_id为空";
            $r['resultCode']= 500;
            View::displayAsJson($r);
            return;
        }
        $gopen_id=(int)$gopen_id;
        $rows=!empty($rows)?(int)$rows:5;
        $page=!empty($page)?(int)$page:1;
        $offset = ($page-1)*$rows;

        list($r['data']['list'],$r['data']['total'])=CommentModule::init('goods_comment','user_id','gopen_id')->getList(null,$gopen_id,$rows,$offset);
        if(!empty($r['data']['list'])){
            foreach ($r['data']['list'] as &$v) {
                $userInfo=UserModule::init('user')->getDetail($v['user_id']);
                //用户名打码

                $arr = str_split($userInfo['username']);
                for($i=3;$i<7;$i++){
                    $arr[$i] = "*";
                }
                $v['username'] = implode($arr);

                ////////
                $userId=$userInfo['id'];
                $userInfoInfo=UserMode::init()->getDetail($userId);
                $lvId=$userInfoInfo['lv_id'];
                $lvInfo=UserMode::init()->getLvInfo($lvId);
                $v['lv']=$lvInfo['name'];
                if(!empty($v['pic_ids'])){
                    $v['pic']=PictureModule::init('picture')->getDetail($v['pic_ids']);
                }else{
                    $v['pic']=null;
                }
            }
        }
        $r['resultCode']= $r['data']['total']>0 ? 200:500;
        View::displayAsJson($r);
    }

    //设置运单号
//    function setExpressTask($order_id,$express_name,$express_num){
//        $r['data'] = OrderMode::init()->setExpress($order_id,$express_name,$express_num);
//        $r['resultCode']= $r['data'] ? 200:500;
//        View::displayAsJson($r);
//    }

} 